<template>
  <div class="app-container customer-div">
    <div style="margin-top: 20px">
      <!--搜索-->
      <el-form :inline="true" :model="params" size="mini" label-width="100px">
        <el-form-item label="订单日期：">
          <el-date-picker
                  :default-time="['00:00:00', '23:59:59']"
                  v-model="params.orderCreated"
                  type="daterange"
                  format="yyyy 年 MM 月 dd 日"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="订单编号：">
          <el-input v-model="params.orderSn"></el-input>
        </el-form-item>
        <el-form-item label="客户：">
          <el-input v-model="params.customerNumber"></el-input>
        </el-form-item>
        <el-form-item label="品名：">
          <el-input v-model="params.goodsName"></el-input>
        </el-form-item>
        <el-form-item label="牌号：">
          <el-select v-model="params.kingGoodsId" filterable placeholder="请选择" clearable>
            <el-option
                    v-for="item in goodsList"
                    :key="item.kingId"
                    :label="item.goodsSn"
                    :value="item.kingId">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="销售员：">
          <el-input v-model="params.purchaseUser"></el-input>
        </el-form-item>
        <el-form-item label="合同流转状态：">
          <el-select v-model.number="params.orderState" class="input-width" style="width:195px" placeholder="请选择" clearable>
            <el-option :value="1" label="手工关闭订单" :key="1"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button
                  @click="handleSearchList()"
                  type="primary">
            查询
          </el-button>
        </el-form-item>
      </el-form>
    </div>
    <!--数据列表-->
    <div class="table-container">
      <el-table
        v-loading="loading"
        :data="list"
        border
        style="width: 100%; margin-top: 20px">
        <el-table-column
                prop="订单日期"
                label="订单日期"
                align="center"
                width="100">
        </el-table-column>
        <el-table-column
                prop="订单编码"
                label="订单编码"
                align="center"
                width="130">
        </el-table-column>
        <el-table-column
                prop="供应商"
                label="客户"
                width="300">
        </el-table-column>
        <el-table-column
                prop="产品编码"
                label="产品编码"
                align="center"
                width="100">
        </el-table-column>
        <el-table-column
                align="center"
                prop="产品名称"
                label="品名"
                width="120">
        </el-table-column>
        <el-table-column
                prop="牌号"
                label="牌号"
                align="center"
                width="180">
        </el-table-column>
        <el-table-column
                prop="销售员"
                label="销售员"
                align="center"
                width="100">
        </el-table-column>
        <el-table-column
                prop="订单数量"
                label="订单数量"
                align="center"
                width="100">
        </el-table-column>
        <el-table-column
                prop="订单单价"
                label="订单单价"
                align="center"
                width="100">
        </el-table-column>
        <el-table-column
                prop="已发货数量"
                label="已发货数量"
                align="center"
                width="100">
        </el-table-column>
        <el-table-column
                prop="系统待发货数量"
                label="系统待发货数量"
                align="center"
                width="130">
        </el-table-column>
        <el-table-column
                prop="实际待发货数量"
                label="实际待发货数量"
                align="center"
                width="130">
        </el-table-column>
        <el-table-column
                prop="单位"
                label="单位"
                align="center"
                width="60">
        </el-table-column>
        <el-table-column
                prop="订单状态"
                label="合同流转状态"
                align="center"
                width="150">
        </el-table-column>
        <el-table-column
                prop="备注"
                label="备注"
                width="300">
        </el-table-column>
      </el-table>
    </div>

    <div class="pagination-container">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        layout="total, sizes,prev, pager, next,jumper"
        :current-page.sync="params.pageNum"
        :page-size="params.pageSize"
        :page-sizes="[10,15,20]"
        :total="count">
      </el-pagination>
    </div>

  </div>
</template>

<script>
    import { saleReportList,orderGoodsList} from '@/api/partner'
    import {formatDate} from '@/utils/date';
    import store from '@/store'
    import { mapGetters } from 'vuex'

    export default {
        name: "saleReport",
        data(){
            return{
                roles:store.getters.roles ? store.getters.roles : [],
                params:{
                  pageNum:1,
                  pageSize:10,
                  orderCreated:null,
                  goodsSn:null,
                  purchaseUser:null,
                  supplierName:null,
                  goodsName:null,
                  orderState:null,
                  orderSn:'',
                  kingGoodsId:'',
                  customerNumber:''
                },
                list:[],
                count:0,
                loading:false,
                goodsList:[]
            }
        },
        computed: {
          ...mapGetters([
            'name',
            'mobile',
            'userId'
          ]),


        },
        created() {
          this.getListData();
          orderGoodsList().then((res)=>{
            this.goodsList = res.list
          })
        },
        filters: {
            formatTime(time) {
                let date = new Date(time);
                return formatDate(date, 'yyyy-MM-dd')
            },
        },
        methods:{
            handleSearchList(){
                this.params.pageNum = 1;
                this.getListData();
            },

            handleSizeChange(val){
                this.params.pageNum = 1;
                this.params.pageSize = val;
                this.getListData();
            },
            handleCurrentChange(val){
                this.params.pageNum = val;
                this.getListData();
            },

            getListData(){
              this.loading = true;
              saleReportList(this.params).then((res)=>{
                this.list = res.list;
                this.count = res.count;
                this.loading = false;
              }).catch(()=>{
                this.loading = false;
              })
            },

        },
    }
</script>

<style scoped lang="scss">
  .avatar-uploader{
    margin-bottom:10px;
    display: inline-block;
    width:80px;
    height:80px;
    border:1px solid #DCDFE6;
    text-align: center;
    line-height: 80px;
  }
</style>
